/*
* Copyright 2010 Competentum group
*
* Licensed under the GNU General Public License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.gnu.org/licenses/gpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.competentum.vos
{
	import com.competentum.events.ValueObjectEvent;
	import com.competentum.history.HistoryChangesManager;
	import com.competentum.io.IXMLCompatible;
	import com.competentum.windows.Scope;
	import com.competentum.lib.data.vo.UniqueVO;
	
	import mx.collections.ArrayList;
	import mx.collections.IList;
	
	
	/**
	 * base class for Value Objects 
	 * @author OsipovS
	 * 
	 */	
	public class AbstractItemVO extends UniqueVO implements IXMLCompatible
	{
		
		/**
		 * counter used to create unique identifiers 
		 */
		public static var currentIndex:uint = 0;
		
		public static const format:String = "vo";
		
		public var scope:Scope;
		
		/**
		 * string label to display in item renderer 
		 */		
		[Bindable]
		public var name:String = "UnNamed";
		
		
		private static const DEFAULT_HOURS:Number = 30;
		
		/**
		 * employee attestation in hours 
		 */		
		[Bindable]
		protected var _hours:Number = DEFAULT_HOURS;
		public function set hours(value:Number):void {
			if ( _hours!=value) {
				_hours = value;
				notifyHolders();
			}
		}
		[Bindable]
		public function get hours():Number {
			return _hours;
		}
		
		public function AbstractItemVO()
		{
		}
		
		
		/**
		 * parts holds all part of current vo
		 * For example, Employee has 40 hours and this hours were devided by 10 and 30 hours
		 * parts uses hours pool from wich hours for project are gathered
		 */		
		[Bindable]
		protected var _bindingsList:IList = new ArrayList();
		/**
		 * This value must be setted from controller using BindBuilder 
		 * @return 
		 * 
		 */		
		public function get bindingsList():IList {
			return _bindingsList;
		}
		public function set bindingsList(value:IList):void {
			_bindingsList = value;
		}
		
		/**
		 * export current vo data to xml 
		 * @return 
		 * 
		 */	
		public /*virtual*/ function exportToXML():XML
		{
			return null;
		}
		
		public function notifyHolders():void
		{
			dispatchEvent(new ValueObjectEvent(ValueObjectEvent.VO_CHANGED, true, true));
		}
	}
}